package Work0603;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Scanner;

/**
 * 4：实现文件剪切的功能，输入一个源文件名，和目标文件夹，剪切后文件名保持不变。
 * 
 * @author Y
 *
 */
public class CutFile {

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		System.out.println("输入要剪切的文件:");
		String a = in.next();
		System.out.println("输入要剪切到的目标文件:");
		String b = in.next();
		File a2 = new File(a);

		String[] a1 = a.split("\\\\");// 将目录以\分开
		b = b + "\\" + a1[a1.length - 1];// 将a的文件名加入b中
		InputStream ab = new FileInputStream(a2);
		OutputStream bc = new FileOutputStream(b);
		byte[] w = new byte[ab.available()];
		int s = ab.read(w);
		bc.write(w, 0, s);// 将ab的字节全部写入bc中
		a2.delete();// 删除剪切的文件
		ab.close();
		bc.close();

	}

}
